/**********************************************************************
 log_util.h
 **********************************************************************

 Synopsis:	Header file for my general logging functions.

 **********************************************************************/

#ifndef LOG_UTIL_H_INCLUDED
#define LOG_UTIL_H_INCLUDED

#include <ebex_util.h>

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>

#include <ebex_lookup.h>
#include <memory_util.h>

/*
 * Constants
 */
#define	LOG_MAX_LEN	160

#define _log_levels(x,_)	\
	_(x, none)				\
	_(x, fatal)				\
	_(x, quiet)				\
	_(x, warning)			\
	_(x, normal)			\
	_(x, verbose)			\
	_(x, extreme)			\
	_(x, fixme)				\
	_(x, debug)

EBEX_LOOKUP_TABLE(log_level, static);


void log_init(e_log_level level, char *fname, bool date);
void log_set_level(e_log_level level);
void log_set_file(const char *fname);
e_log_level log_get_level(void);

/*
 * This is the actual logging function, but isn't intended to be used
 * directly.
 */
void log_output(const e_log_level level, const char *func_name, const char *file_name, const int line_num,
		const char *format, ... ) __attribute__((format(printf, 5, 6)));

#define	elog( level, ... ) { 					\
	if ( (level) <= log_get_level() ) 			\
	  log_output(level, __func__,	\
	                   __FILE__, __LINE__,		\
	                   ##__VA_ARGS__); }


#endif /* LOG_UTIL_H_INCLUDED */

